<script setup lang="ts">
import { storeToRefs } from 'pinia'
import useUserStore from '@/stores/user.ts'
import { onMounted, watch } from 'vue'
import { SupplyChainStatistics } from '@/api/order.ts'
import { useMenus } from '@/stores/menus.ts'

const { user } = storeToRefs(useUserStore())
const { updateMenu } = useMenus()

const onUserChange = async (u?: IUser) => {
  if (u?.role_type === 2) {
    const statistics = await SupplyChainStatistics()
    updateMenu('/order/supporter-post-orders', statistics.data.wait_delivery_count)
  }
}

onMounted(() => onUserChange(user.value))
watch(user, u => onUserChange(u))

</script>

<template>

</template>